package com.akami.util;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import xframe.conf.Constants;
import xframe.ctl.XDispatchAction;
import xframe.util.AutoMapper;
import xframe.util.DynamicVar;
import xframe.util.db.Row;

public class WebHard extends XDispatchAction{
	
	public ActionForward move( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {

			Row	req			=	getRequestInfo(request);
		
		return mapping.findForward((String) req.get("NEXT_PAGE") );
	}
	
	public ActionForward fileUpload( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {

		String savePath=DynamicVar.get("webhard.path2");	// 저장할 디렉토리 (절대경로)
        int sizeLimit = 200 * 1024  * 1024 ;      // 파일업로드 용량 제한.. 100Mb
        int attachment_size =0;
        AutoMapper mapper	= null;
        HashMap	req			=	new HashMap();
        
        try{
        	/**
             * @see  : Multipart를 처리하기 위해 구현된 함수로 내부 접근 함수를 통해서 hashmap으로 받을 수 있다.
             * 예>  AutoMapper mapper = new AutoMapper(request, savePath,sizeLimit, "euc-kr", Constant.UPLOAD_currentTimeMillis_NAME_RULE);
             * @param request  : HttpServletRequest
             * @param savePath  : 파일이 저장될 위치
             * @param pathPlus  : 파일이 저장될 위치의  sub 디렉토리명
             * @param sizeLimit  : 파일의 제한용량 byte 기준(1024*1024*10=>10Mb)가된다.
             * @param request  : HttpServletRequest
             * @param request  : HttpServletRequest
             * @return :  생성자 함수
             */         	
        mapper	=	new AutoMapper(request, savePath, "data", sizeLimit, Constants.UPLOAD_REAL_NAME_RULE);
        req		= mapper.getMutlpartParam();
    
	
        
		ArrayList fileInfo = mapper.getFiles();

		
				
				//String queryName	=	"board.attach_file";
				//String query 		=	mappingQuery(req, queryName);
						
				//PreparedStatement 용 parameter 순서 설정
				/*String[] preparedIndex = {
						"message_id",            
						"attachment_type",            
						"file_name",               
						"file_path",               
						"file_size",
						"file_ext",
						"saved_file_name",
						"pre_pk"
						};
				for(int i =0; i < fileInfo.size() ; i++){
			            UploadFile file =(UploadFile) fileInfo.get(i);
			            req.put("file_ext", file.getExe());
			            req.put("file_name", file.getFileName());
			            req.put("file_path", StringUtils.remove(file.getDirectoryPath(), DynamicVar.get("board.boardRoot")));
			            req.put("file_size", file.getSize()+"");
			            attachment_size += file.getSize();
			            req.put("saved_file_name", file.getRenamedFile());
			            req.put("attachment_type", Constants.UPLOAD_ATTACH_FILE_TYPE_TXT+"");
						PreparedStatement  실행
						preparedExecuteUpdate(request, req, preparedIndex, query);
			        }*/
			}catch(Exception e){
				e.printStackTrace();
			}
		
        return mapping.findForward("blank");				
		
	}
	
}
